package com.gelsanalyzer.business;

import java.util.*;

import org.apache.commons.logging.*;
import org.hibernate.*;

import com.gelsanalyzer.core.*;

/**
 * MapGELS is a class that returns the applicable
 * <code>List<Course></code> or <code>List<Goalarea></code> based on what
 * was requested.
 * 
 * @author Jared Olhoft
 */
public class MapGELS {
    private static final Log log = LogFactory.getLog(DepartmentHome.class);
    private static final SessionFactory sessionFactory = HibernateUtil
        .getSessionFactory();

    private MapGELS() {
    }

    public static List<Goalarea> getGoalArea(Course c) {
        if (c == null) {
            return null;
        }
        
        log.debug("finding all Goalarea instances given Course");
        try {
            Session session = sessionFactory.getCurrentSession();
            session.beginTransaction();

            List<Goalarea> goalList = (List<Goalarea>) session
                .createQuery(
                    "from Goalarea ga where ga.goalareaGoalnum IN (select m.goalareaGoalnum from MapCourseGoalarea m where m.courseId = "
                            + c.getCourseId() + " ) ").list();

            session.getTransaction().commit();

            log.debug("find All Goalareas successful, result size: "
                    + goalList.size());

            return goalList;
        } catch ( RuntimeException re ) {
            log.error("find by Course failed", re);
            throw re;
        }
    }

    public static List<Course> getCourses(Goalarea ga) {
        // TODO: will do a direct query against the DB and come back with a list
        // of the Courses that apply to the given Goalarea.

        return null;
    }
}
